// FeedFetcher.h: interface for the FeedFetcher class.
//
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_FEEDFETCHER_H__5A4A1A41_5F51_4C1E_8933_7063EC3C94D4__INCLUDED_)
#define AFX_FEEDFETCHER_H__5A4A1A41_5F51_4C1E_8933_7063EC3C94D4__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include "RSSParser.h"
#include "RSSFeed.h"
#include "FeedGroup.h"
#include "DBManager.h"
#include "WebGrab.h"

class FetchProgressHandler
{
public:
	virtual void OnFinishFetchAFeed(int nID, int nNum){
		return;
	}
};

// a singletion, which is used to fetch RSS feeds
class FeedFetcher  
{
	friend class AutoFeedFetcherCloser;
protected:
	FeedFetcher();
	static FeedFetcher* pInstance;
	static const char* strAgentName;
public:
	void SetFPH(FetchProgressHandler* FPH){
		m_FPH = FPH;
	}
	void WorkerThreadProc();
	static UINT ThreadProc(LPVOID pParam );
	bool CreateWorkerThread();
	static FeedFetcher* Instance();
	virtual ~FeedFetcher();
	
	bool FetchAGroup(int nID);
	bool FetchAGroup(FeedGroup* pGroup);
	bool FetchAFeed(int nID);
	bool FetchAFeed(RSSFeed* pFeed);
	void StopFetching();

	bool RunFetchAFeed(int nID);
private:
	CWinThread* m_pWorkerThread;
	int m_bRunning;
	queue<int> m_ToFetchFeeds;
	
	CRITICAL_SECTION m_cs;
private:
	FetchProgressHandler* m_FPH;
	CWebGrab m_grabber;	
};

#endif // !defined(AFX_FEEDFETCHER_H__5A4A1A41_5F51_4C1E_8933_7063EC3C94D4__INCLUDED_)
